<template>
	<view>
		<view class="tabBox">
			
		</view>
		<view class="waitListBox">
			<mescroll-body ref="mescroll" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
				<block v-for="(item, index) in waitList" :key="index">
					<view class="column-css view-cente">
						<view class="time">
							{{item.operationTime}}
						</view>
						<view class="bgW">
							<view class="headBox">
								<image src="../../static/icon_client.png" mode=""></image>
								<text>{{item.title}}</text>
							</view>
							<view>
								<view v-if="item.titleType == 1 || item.titleType == 2 || item.titleType == 3">
									<!-- 1-驾驶证到期提醒
									2-身份证到期提醒
									3-道路运输从业资格证到期提醒 -->
									<view class="waitWord">
										<p>{{ item.content }}</p>
										<p>司机姓名： {{item.driverName}}</p>
										<p>有效期： {{item.validityPeriod}}</p>
									</view>
									<view class="waitBtn"  @click="onDetail(item)">
										立即更新>>>
									</view>
								</view>
								<view v-if="item.titleType == 4">
									<!-- 道路运输证到期提醒 -->
									<view class="waitWord">
										<p>{{ item.content }}</p>
										<p>车牌号： {{item.driverName}}</p>
										<p>有效期： {{item.validityPeriod}}</p>
									</view>
									<view class="waitBtn"  @click="onDetail(item)">
										立即更新>>>
									</view>
								</view>
								<view v-if="item.titleType == 5">
									<!-- 账户资质提醒 司机-->
									<view class="waitWord">
										<p>{{ item.content }}</p>
										<p>司机姓名： {{item.driverName}}</p>
										<p>申诉状态：<text style="color: #ff1606;">已驳回</text></p>
										<p>驳回原因：{{item.reason}}</p>
									</view>
									<view class="waitBtn"  @click="onDetail(item)">
										立即更新>>>
									</view>
								</view>
								<view v-if="item.titleType == 6">
									<!-- 账户资质提醒 车辆-->
									<view class="waitWord">
										<p>{{ item.content }}</p>
										<p>车牌号： {{item.driverName}}</p>
										<p>申诉状态：<text style="color: #ff1606;">已驳回</text></p>
										<p>驳回原因：{{item.reason}}</p>
									</view>
									<view class="waitBtn"  @click="onDetail(item)">
										立即更新>>>
									</view>
								</view>
								<view v-if="item.titleType == 7">
									<!-- 账户资质提醒 车辆-->
									<view class="waitWord">
										<p>{{ item.content }}</p>
										<p>司机姓名： {{item.driverName}}</p>
										<p>申诉状态：<text style="color: #ff1606;">已驳回</text></p>
										<p>驳回原因：{{item.reason}}</p>
										<p>驳回时间：{{item.operationTime}}</p>
									</view>
								</view>
								<view v-if="item.titleType == 8">
									<!-- 账户资质提醒 车辆-->
									<view class="waitWord">
										<p>{{ item.content }}</p>
										<p>司机姓名： {{item.driverName}}</p>
										<p>申诉状态：<text style="color: #2979ff;">已通过</text></p>
										<p>通过时间：{{item.operationTime}}</p>
									</view>
								</view>
								<view v-if="item.titleType == 9">
									<!-- 活体认证 -->
									<view class="waitWord">
										<p>{{ item.content }}</p>
										<p>司机姓名： {{item.driverName}}</p>
										<p>人脸活体认证：<text>未认证</text></p>
									</view>
									<view class="waitBtn"  @click="onDetail(item)">
										立即更新>>>
									</view>
								</view>
								<view v-if="item.titleType == 10">
									<!-- 协议签署状态 -->
									<view class="waitWord">
										<p>{{ item.content }}</p>
										<p>司机姓名： {{item.driverName}}</p>
										<p>协议签署状态：<text>未签署</text></p>
									</view>
									<view class="waitBtn"  @click="onDetail(item)">
										前往签署>>>
									</view>
								</view>
								<view class="waitBtn" v-if="item.operationType == 1"  @click="onDetail(item)">
									立即更新>>>
								</view>
								<view v-if="item.titleType == 11">
									<!-- 协议签署状态 -->
									<view class="waitWord">
										<p>{{ item.content }}</p>
										<p>委托方： {{item.driverName}}</p>
										<p>配载单号：<text>{{item.loadingOrderNo}}</text></p>
									</view>
									<view class="waitBtn">
										<view class="waitBotton" @click="operateLoadingOrder(3,item)">
											驳回
										</view>
										<view class="waitBotton"  @click="operateLoadingOrder(4,item)">
											确认作废
										</view>
									</view>
								</view>
							</view>
						</view>
						
					</view>
				</block>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
	import MescrollBody from '@/uni_modules/mescroll-uni/components/mescroll-body/mescroll-body.vue';
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			MescrollBody
		},
		data() {
			return {
				etpId:uni.getStorageSync(this.DATA_KEY.etpId),
				messageCount: '',
				waitDoCount: '',
				seledTab: '1',
				driverId: uni.getStorageSync(this.DATA_KEY.userInfo).driverId,
				DriverMessageBusiness:'',
				DriverMessageCapital:'',
				DriverMessageCertification:'',
				buesinessNum: '',
				capiatlNum: '',
				certificationNum: '',
				waitList: [],
				page: 1,
				pageSize: 10,
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					}
				}
			}
		},
		onLoad: function(options) {
		},
		onShow: function() {
			this.onwaybill()
		},
		methods: {
			//待办的方法
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调*/
			downCallback(mescroll) {
				mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
			},
			/*上拉加载的回调*/
			upCallback(mescroll) {
				this.page = mescroll.num; // 页码, 默认从1开始
				//联网加载数据
				this.onwaybill(mescroll);
			},
			//获取待办事项
			onwaybill(mescroll) {
				this.wxRequest({
					url: `${this.API}/driverMessageCertification/queryList`,
					method: 'POST',
					data: {
						"driverId": this.driverId,
						  "pageNum": this.page,
						  "pageSize": this.pageSize,
						  "type":"1",
							etpId: uni.getStorageSync(this.DATA_KEY.etpId)
					},
					title: '加载中...',
					success: res => {
						let list = res.data.data.list;
						if (this.page == 1) {
							this.waitList = [];
						}
						for (let i = 0; i < list.length; i++) {
							this.waitList.push(list[i]);
						}
						if (mescroll != null) {
							mescroll.endBySize(this.waitList.length, res.data.data.total);
							setTimeout(() => {
								this.mescroll.endSuccess(this.waitList.length);
							}, 20);
						}
					}
				})
			},
			//跳转到对应页面
			onDetail(val){
				console.log(val)
				console.log(val.titleType)
				if(val.titleType == 4 || val.titleType == 6 || val.titleType == 7 || val.titleType == 8 ){
					if( val.titleType == 7 || val.titleType == 8 ){
						return false
					}
					uni.navigateTo({
						url:`/pages/vehicle/vehicleinformation?vehicleId=` + val.vehicleId+'&etp_id=' + this.etpId 
					});
					// uni.navigateTo({
					// 	url: `/pages/personal/driverregistration?type=${val}`
					// });
				}else if(val.titleType == 9){
					this.shake()
				}else if(val.titleType == 10){
					uni.navigateTo({
						url: `/pages/personal/signinglist`
					});
				}else if(val.titleType == 11){
					return false
				}else{
					uni.navigateTo({
						url: `/pages/personal/driverregistration?type=${val}`
					});
				}
				
			},
			allRead(id){
				let data = {
					  "driverId": this.driverId,
					  "tableName": 'driver_message_certification',
					  "id": id,
				}
				this.wxRequest({
					url: `${this.API}/driverMessageCommon/updateMessageStatus`,
					method: 'POST',
					data: data,
					success: res => {
						if(res.data.code == 0){
							// uni.showToast({
							// 	title: '',
							// 	icon: 'none'
							// });
							// this.onwaybill()
						}
					}
				})
			},
			operateLoadingOrder(val,item){
				let that = this
				uni.showModal({
					title: '提示',
					content: val==3?'将驳回当前作废申请，确认吗?':'将作废当前配载单，确认吗?',
					success: function(res) {
						if (res.confirm) {
							that.wxRequest({
								url: `${that.API}/new/loadingOrder/operateLoadingOrder?loadingOrderId=${item.loadingOrderId}&operate=${val}&driverId=${that.driverId}`,
								method: 'POST',
								data: {  "driverId": that.driverId },
								success: res => {
									uni.showToast({
										title: '操作成功',
										icon: 'none'
									});
								}
							})
						} else if (res.cancel) {
							console.log('取消');
						}
					}
				});
			},
			shake() {
				console.log(this.timer,"oooooo")
				
			    if (this.timer) {
			        // clearTimeout(this.timer)
					return
			    }
				this.livingcertification()
			    this.timer = setTimeout(() => {
					console.log(888888)
			    }, 3000)
			},
			livingcertification() {
				// if (this.user.livingBodyState == 0) {
					console.log('dayin' ,111111111111)
					console.log(uni.getStorageSync(this.DATA_KEY.userInfo).driverId ,111111111111)
					let that = this;
					that.wxRequest({
						url: `${that.API}/driverService/getDriverIdCardInfo`,
						method: 'POST',
						data: {
							driverId: that.driverId,
							platformCoNo: uni.getStorageSync(this.DATA_KEY.platformCoNo)
						},
						title: '加载中...',
						success: res => {
							let accessToken = res.data.data.accessToken; //认证令牌
							this.accessToken = accessToken
							let taxNumber = res.data.data.taxNumber; //平台税号
							let realName = res.data.data.driverName;
							let idCard = res.data.data.idcard;
							let idPhotoUp = res.data.data.idcard1Base64;
							let idPhotoDown = res.data.data.idcard2Base64;
							that.wxRequestData({
								url: `${that.API2}/api/face/getFaceQRCode?access_token=` + accessToken,
								method: 'POST',
								title: '加载中...',
								data: {
									companyTaxNumber: taxNumber,
									realName: realName,
									idCard: idCard,
									idPhotoUp: idPhotoUp,
									idPhotoDown: idPhotoDown,
									callbackUrl: `${that.API}/driverService/isLivingBodyState`
								},
								success: res => {
									console.log("===================>2",res);
									if (res.data.code == 0) {
										let orderNumber = res.data.data.orderNumber;
										this.orderNumber = orderNumber
										let that = this
										that.wxRequest({
											url: `${that.API}/driverService/saveFaceVerifyOrderNumber`,
											method: 'POST',
											data: {
												driverId: that.driverId,
												orderNumber: orderNumber,
												platformCoId: uni.getStorageSync(this.DATA_KEY.platformCoNo) == '0001' ? '100001' : '100002'
											},
											success: res => {
												// #ifdef APP-PLUS
												uni.showModal({
													title: '提示',
													content: '是否去进行实名认证?跳转进行实名认证后需要重新打开当前APP!',
													success: function(res) {
														if (res.confirm) {
															console.log('用户点击确定');
															that.timer = null
															that.flag = true
															plus.share.getServices(
																function(res) {
																	var sweixin = null;
																	console.log(res);
																	for (var i = 0; i < res.length; i++) {
																		var t = res[i];
																		console.log(t);
																		if (t.id == 'weixin') {
																			sweixin = t;
																		}
																	}
																	if (sweixin) {
																		console.log('dddd=', 'a=' + sweixin + '=b');
																		sweixin.launchMiniProgram({
																			// id: 'gh_cec8224b00da',
																			id: 'gh_45eec401ff1c',
																			type: 0, //0-正式版 1.测试版，2，体验版
																			path: 'pages/verify/info/index?id=' + orderNumber
																		});
																	}
																},
																function(res) {
																	console.log(JSON.stringify(res));
																}
															);
														} else if (res.cancel) {
															console.log('用户点击取消');
															that.timer = null
														}
													}
												});
												// #endif
												
												// #ifdef MP-WEIXIN
												uni.showModal({
													title: '提示',
													content: '是否去进行实名认证?',
													success: function(res) {
														if (res.confirm) {
															that.timer = null
															console.log(that.timer)
															
															that.flag = true
															console.log('用户点击确定');
															uni.navigateToMiniProgram({
																// appId: 'wxfd2861dc1c86b3a0',
																appId: 'wxfc1e27e05fdd062b',
																// path: 'pages/verify/info/index?id=' + orderNumber,
																path: 'pages/verify/info/index?id=' + orderNumber,
																envVersion: 'release',
																success(res) {
																	console.log('跳转成功');
																},
																fail(res) {
																	console.log('跳转失败' + JSON.stringify(res));
																}
															});
														} else if (res.cancel) {
															that.timer = null
															console.log(that.timer)
															console.log('用户点击取消');
														}
													}
												});
												// #endif
											}
										});
									}
								}
							});
						}
					});
				// }
			},
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
		height: 100%;
	}
	.allRead{
		text-align: right;
		color: #aab3bc;
		padding: 20rpx;
	}
	.row-css {
		display: flex;
		flex-direction: row;
	}

	.column-css {
		display: flex;
		flex-direction: column;
		margin: 20rpx;
	}
	.waitListBox{
		background-color: #efeeee;
		.column-css{
			font-size: 28rpx;
			.time{
				text-align: center;
				font-size: 32rpx;
				color: #8b929a;
				line-height: 80rpx;
			}
			.bgW{
				background: #FFF;			
				padding: 30rpx 30rpx 0 30rpx;
				border-radius: 8rpx;
			}
		}
		.headBox{
			display: flex;
			line-height: 60rpx;
			font-size: 34rpx;
			color: #2979ff;
			image{
				width:60rpx;
				height: 60rpx;
				margin-right: 20rpx;
			}
		}
		.waitWord{
			font-size: 32rpx;
			padding-top: 20rpx;
			color: #8b929a;
			padding-bottom: 60rpx;
			border-bottom: 1rpx solid #e3e3e3;
			p{
				line-height: 40rpx;
				margin-bottom: 10rpx;
				.seltext{
					color: #ff0101;
				}
				.getText{
					color: #2979ff;
				}
			}
		}
		.waitBtn{
			text-align: center;
			color: #2979ff;
			line-height: 90rpx;
		}
	}
</style>
